package com.gitee.wsl.doc.prosemirror.model.fragment.ext

import com.gitee.wsl.doc.prosemirror.model.fragment.Fragment

fun addToFragment(fragment: Fragment, depth: Int, content: Fragment): Fragment {
    if (depth == 0) return fragment.append(content)
    return fragment.replaceChild(
        fragment.childCount - 1,
        fragment.lastChild!!.copy(addToFragment(fragment.lastChild!!.content, depth - 1, content))
    )
}

fun Fragment.add(depth: Int, content: Fragment): Fragment = addToFragment(this,depth,content)